package com.ciaojian.store.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.ciaojian.core.enums.business.OrderBusinessType;
import com.ciaojian.core.model.Store;
import com.ciaojian.core.util.Result;
import com.ciaojian.store.service.StoreServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author Atlakyn
 */
@Api(tags = "门店")
@RestController
@RequestMapping("/stores")
public class StoreController {
    @Resource
    private StoreServiceImpl storeService;

    @ApiOperation("全部门店")
    @GetMapping
    public Result allStore() {
        LambdaQueryWrapper<Store> wrapper = new LambdaQueryWrapper<>();
//        wrapper.eq(Store::getIsDel, 0);
//        wrapper.eq(Store::getIsHidden, 0);
        wrapper.eq(Store::getBusinessType, 0);
        return Result.ok(new Store().selectList(wrapper));
    }

    @ApiOperation(value = "加盟商门店列表", response = Store.class)
    @GetMapping("/franchisees/{franchiseesId}")
    public Result getByFranchisees(@ApiParam("加盟商Id") @PathVariable String franchiseesId) {
        LambdaQueryWrapper<Store> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(Store::getFranchiseesId, franchiseesId)
                .eq(Store::getBusinessType, OrderBusinessType.normal);
        return Result.ok(storeService.list(lambdaQueryWrapper));
    }


}
